package com.an.homework;

public class HomeWork_5 {
    public static void main(String[] args) {
        Person person = new Person("唐僧",new Horse());//接口传值传完成接口的类
        person.commen();
        person.passriver();


    }
}

interface Vehicles{
    public void work();
}

class Horse implements Vehicles{
    public void work(){
        System.out.println("我是马+7");
    }
}

class Boat implements Vehicles{
    public void work(){
        System.out.println("我是小船");
    }
}

class Tools{
    public static Horse gethorse(){
        return new Horse();
    }
    public static Boat getboat(){
        return new Boat();
    }

}

class Person {
    private String name;
    Vehicles vehicles;

    public Person(String name, Vehicles vehicles) {
        this.name = name;
        this.vehicles = vehicles;
    }
    public void commen(){
        if(!(vehicles instanceof Horse)){
            vehicles=Tools.gethorse();
            vehicles.work();
        }
        else {
            vehicles.work();
        }
    }
    public void passriver(){
        //过河得用船
        if(!(vehicles instanceof Boat)){
            vehicles=Tools.getboat();
            vehicles.work();
        }
        else{
            vehicles.work();
        }
    }
}
//
//class PassRiver{
//    public void commen(Vehicles vehicles){
//        if(!(vehicles instanceof Horse)){
//            vehicles=Tools.gethorse();
//            vehicles.work();
//        }
//        else {
//            vehicles.work();
//        }
//    }
//
//    //过河
//    public void passriver(Vehicles vehicles){
//        //过河得用船
//        if(!(vehicles instanceof Boat)){
//            vehicles=Tools.getboat();
//            vehicles.work();
//        }
//        else{
//            vehicles.work();
//        }
//    }
//}